package com.itheima.controller;


import com.itheima.commo.PageResult;
import com.itheima.commo.R;
import com.itheima.dto.DishDto;
import com.itheima.dto.SetmealDto;
import com.itheima.entity.Dish;
import com.itheima.entity.Setmeal;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 套餐管理控制层
 */
@RequestMapping("/setmeal")
@RestController
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     */
    @PostMapping
        public R<String> save(@RequestBody SetmealDto setmealDto){
        setmealService.saveAdd(setmealDto);
        return R.success("新增套餐成功");
    }


    /**
     * 套餐分页查询
     */
    @GetMapping("/page")
    public R<PageResult> findPage(@RequestParam(value = "page", defaultValue = "1") Long page,
                                  @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize, String name) {
        PageResult<SetmealDto> pageResult = setmealService.findPage(page, pageSize,name);
        return R.success(pageResult);
    }

    /**
     * 删除套餐  List<Long> ids  一定要加上@RequestParam
     */
    @DeleteMapping
    public R<String> delete(@RequestParam List<Long> ids){
        setmealService.delete(ids);
        return R.success("删除套餐成功了");

    }

    /**
     * 查询套餐数据
     */
    @GetMapping("/list")
    public R<List<Setmeal>> list(Setmeal setmeal){
        List<Setmeal> list = setmealService.list(setmeal);
        return R.success(list);
    }

    /**
     * 套餐批量启售 停售
     */
    @PostMapping("/status/{status}")
    public R<Setmeal> statusA(@PathVariable Integer status, @RequestParam List<Long> ids){
        return setmealService.statusA(status, ids);
    }


    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    public R<SetmealDto> findById(@PathVariable("id") Long id){
        return R.success(setmealService.findById(id));
    }

    /**
     * 套餐修改
     */
    @PutMapping
    public R<String> update(@RequestBody SetmealDto setmealDto){
        setmealService.update(setmealDto);
        return R.success("修改套餐信息信息成功了");
    }


}
